package com.simplefan.system.common.Rest;

import net.sf.json.JSONObject;

import com.simplefan.framework.common.rest.RestObjectAnalyzer;

public class PoRestObjectAnalyzer<T> implements RestObjectAnalyzer<T>{

  public T toValue(String xmlFragment) {
    if (xmlFragment != null && !xmlFragment.equals("null")) {
      return (T) JSONObject.fromString(xmlFragment);
    }
    else {
      return null;
    }
  }

  public String toXmlFragment(T value) {
    if (value == null) {
      return "null";
    }

    return JSONObject.fromBean(value).toString();
  }
}
